home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Mark Pilgrim / MSG Demo 1.4 / source / Demo ƒ / demo graphics.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-30  |  3.4 KB  |  144 lines  |  [TEXT/KAHL]

  1. /**********************************************************************\
  2.  
  3. File:        demo graphics.c
  4.  
  5. Purpose:    This module handles updating the main window (via the
  6.             offscreen bitmaps).
  7.  
  8. This program is free software; you can redistribute it and/or modify
  9. it under the terms of the GNU General Public License as published by
  10. the Free Software Foundation; either version 2 of the License, or
  11. (at your option) any later version.
  12.  
  13. This program is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. GNU General Public License for more details.
  17.  
  18. You should have received a copy of the GNU General Public License
  19. along with this program in a file named "GNU General Public License".
  20. If not, write to the Free Software Foundation, 675 Mass Ave,
  21. Cambridge, MA 02139, USA.
  22.  
  23. \**********************************************************************/
  24.  
  25. #include "graphics.h"
  26. #include "demo graphics.h"
  27. #include "util.h"
  28. #include "program globals.h"
  29.  
  30. /* internal procedures for demo graphics.c only */
  31. void SetupTheMainWindow(WindowDataHandle theData);
  32. void OpenTheMainWindow(WindowDataHandle theData);
  33. void ShutdownTheMainWindow(WindowDataHandle theData);
  34. void DrawTheMainWindowColor(void);
  35. void DrawTheMainWindowBW(void);
  36.  
  37. PicHandle        gPic1ColorPict;
  38. PicHandle        gPic1BWPict;
  39. PicHandle        gPic2ColorPict;
  40. PicHandle        gPic2BWPict;
  41.  
  42. enum
  43. {
  44.     kPic1ColorID=200,
  45.     kPic2ColorID,
  46.     kPic1BWID,
  47.     kPic2BWID
  48. };
  49.  
  50. int MainWindowDispatch(ExtendedWindowDataHandle theData, int theMessage, unsigned long misc)
  51. {
  52.     int                theDepth;
  53.     
  54.     switch (theMessage)
  55.     {
  56.         case kUpdate:
  57.             theDepth=misc&0x7fff;
  58.             if (theDepth>2)
  59.                 DrawTheMainWindowColor();
  60.             else
  61.                 DrawTheMainWindowBW();
  62.             return kSuccess;
  63.             break;
  64.         case kOpen:
  65.             OpenTheMainWindow(theData);
  66.             return kSuccess;
  67.             break;
  68.         case kStartup:
  69.             SetupTheMainWindow(theData);
  70.             return kSuccess;
  71.             break;
  72.         case kShutdown:
  73.             ShutdownTheMainWindow(theData);
  74.             return kSuccess;
  75.             break;
  76.     }
  77.     
  78.     return kFailure;
  79. }
  80.  
  81. void SetupTheMainWindow(WindowDataHandle theData)
  82. {
  83.     unsigned char    *titleStr="\pMSG Demo";
  84.     
  85.     (**theData).windowWidth=500;
  86.     (**theData).windowHeight=300;
  87.     (**theData).windowType=noGrowDocProc;
  88.     (**theData).hasCloseBox=TRUE;
  89.     Mymemcpy((**theData).windowTitle, titleStr, titleStr[0]+1);
  90.     gPic1ColorPict=gPic1BWPict=gPic2ColorPict=gPic2BWPict=0L;
  91.     OpenTheWindow((**theData).windowIndex);
  92. }
  93.  
  94. void OpenTheMainWindow(WindowDataHandle theData)
  95. {
  96.     (**theData).offscreenNeedsUpdate=TRUE;
  97. }
  98.  
  99. void ShutdownTheMainWindow(WindowDataHandle theData)
  100. {
  101.     if (ReleaseThePict(gPic1ColorPict))
  102.         gPic1ColorPict=0L;
  103.     if (ReleaseThePict(gPic1BWPict))
  104.         gPic1BWPict=0L;
  105.     if (ReleaseThePict(gPic2ColorPict))
  106.         gPic2ColorPict=0L;
  107.     if (ReleaseThePict(gPic2BWPict))
  108.         gPic2BWPict=0L;
  109. }
  110.  
  111. void DrawTheMainWindowColor(void)
  112. {
  113.     RGBColor    oldForeColor, oldBackColor;
  114.     
  115.     GetForeColor(&oldForeColor);
  116.     GetBackColor(&oldBackColor);
  117.     
  118.     if (!gWhichWipe)
  119.         gWhichPict=!gWhichPict;
  120.     if (gWhichPict)
  121.         DrawThePicture(&gPic1ColorPict, kPic1ColorID, 0, 0);
  122.     else
  123.         DrawThePicture(&gPic2ColorPict, kPic2ColorID, 0, 0);
  124.     
  125.     if (!gWhichWipe)
  126.         gWhichPict=!gWhichPict;
  127.     
  128.     RGBForeColor(&oldForeColor);
  129.     RGBBackColor(&oldBackColor);
  130. }
  131.  
  132. void DrawTheMainWindowBW(void)
  133. {
  134.     if (!gWhichWipe)
  135.         gWhichPict=!gWhichPict;
  136.     if (gWhichPict)
  137.         DrawThePicture(&gPic1BWPict, kPic1BWID, 0, 0);
  138.     else
  139.         DrawThePicture(&gPic2BWPict, kPic2BWID, 0, 0);
  140.     
  141.     if (!gWhichWipe)
  142.         gWhichPict=!gWhichPict;
  143. }
  144.